## Script (Python) "getProjectTasks"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=project
##title=getProjectTasks
##

""" Get a dictionary with a projects tasks and info """

tasks = context.portal_catalog.searchResults(portal_type=('Task',), path={'query':'/'.join(project.getPhysicalPath()),}, sort_on='Date', sort_order='reverse',)

taskDict = {}
taskList = []
estimated = 0
used = 0

if len(tasks) > 0:

  for task in tasks:
    taskList.append(task)
    if task.getEstimated_hours != None:
      estimated = estimated + task.getEstimated_hours
    if task.getUsed_hours != None:
      used = used + task.getUsed_hours
            
  if used != 0 and estimated != 0:
      projectProgress = (used*100)/estimated
  else:
      projectProgress = 0

else:

  taskList = []
  estimated = 0
  used = 0
  projectProgress = 0
  
  
taskDict['tasks']=taskList
taskDict['estimated']=estimated
taskDict['used']=used
taskDict['progress']= projectProgress

return taskDict

